package com.hspedu.newData.dmsxl;

import org.junit.Test;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-14 
 * @Version: 1.0
 */

public class Test1 {

    public int f1(int[] nums){

        if (nums.length == 1) return nums[0];

        int j = nums[0];
        for (int i = 1; i < nums.length; i++) {
            j ^= nums[i];
        }
        return j;
    }

    public int f2(String s){

        HashSet<Character> set = new HashSet<>();
        int slow = 0;
        int fast = 0;

        int max = 0;
        while(fast < s.length()){
            while (set.contains(s.charAt(fast))){
                set.remove(s.charAt(slow));
                slow++;
            }
            set.add(s.charAt(fast++));
            if (max < fast - slow){
                max = fast - slow;
            }
        }

        return max;
    }


    @Test
    public void test() {
        // 测试代码
//        f1(new int[]{4,4,1,2,1,2,3});
        f2("abcabcdabcbb");
    }


}
